package com.sample.wanandroidx.ui.home

import com.google.android.material.bottomnavigation.BottomNavigationView
import com.sample.wanandroidx.R
import com.sample.wanandroidx.adapter.HomeFragmentAdapter
import com.sample.wanandroidx.basic.BaseActivity
import com.sample.wanandroidx.databinding.ActivityMainBinding
import com.sample.wanandroidx.ui.fragment.ClassificationFragment
import com.sample.wanandroidx.ui.fragment.HomeFragment
import com.sample.wanandroidx.ui.fragment.UserFragment

open class MainActivity : BaseActivity<ActivityMainBinding>(ActivityMainBinding::inflate) {

    override fun useEventBus() = true

    override fun initialization() {
        val fragments = mutableListOf(HomeFragment.newInstance(0),
            ClassificationFragment(),
            HomeFragment.newInstance(1),
            HomeFragment.newInstance(2),
            UserFragment())
        binding.viewpager.isUserInputEnabled = false
        binding.viewpager.adapter = HomeFragmentAdapter(this, fragments)
        binding.viewpager.offscreenPageLimit = fragments.size - 1
        binding.navView.setOnNavigationItemSelectedListener(onItemSelectedListener)
        //binding.navView.selectedItemId = R.id.ic_baseline_person
    }

    private val onItemSelectedListener = BottomNavigationView.OnNavigationItemSelectedListener { item ->
        when (item.itemId) {
            R.id.ic_baseline_home -> binding.viewpager.setCurrentItem(0, false)
            R.id.ic_baseline_category -> binding.viewpager.setCurrentItem(1, false)
            R.id.ic_baseline_crop_square -> binding.viewpager.setCurrentItem(2, false)
            R.id.ic_baseline_question_answer -> binding.viewpager.setCurrentItem(3, false)
            R.id.ic_baseline_person -> binding.viewpager.setCurrentItem(4, false)
        }
        true
    }

    override fun onBackPressed() {
        super.backPress()
    }



}
